package com.wyzz.hr.io.extend;

import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;

import com.wyzz.hr.bo.AuthorityPosBo;
import com.wyzz.hr.bo.IEmployeeBo;
import com.wyzz.hr.bo.IWorkFlowBO;
import com.wyzz.hr.pojo.Employee;
import com.wyzz.hr.spring.SpringBeanFactory;

public abstract class ICheckAndInsert {

	public ICheckAndInsert() {
		noAuth = "\u60A8\u5BF9{0}\u65E0\u6392\u73ED\u6743\u9650\uFF01";
		employeeBo = (IEmployeeBo) SpringBeanFactory.getBean("empBo");
	}

	public abstract int[] insertTransmit(List list,
			CommonParameters commonparameters) throws Exception;

	public Map getNameIdMap(String clazz, String id, String name,
			String condition[]) {
		List rs = employeeBo.exeHqlList(clazz, new String[] { id, name },
				condition);
		Map result = new HashMap();
		Object objArr[];
		for (Iterator i$ = rs.iterator(); i$.hasNext(); result.put(
				(String) objArr[1], (String) objArr[0]))
			objArr = (Object[]) i$.next();

		return result;
	}

	public List getEmployeeList() {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(Employee.class);
		detachedCriteria.addOrder(Order.asc(Employee.PROP_EMP_DISTINCT_NO));
		return employeeBo.findByCriteria(detachedCriteria);
	}

	public void chechDeptAuth(Employee currentEmp, String empIdArr[],
			CommonParameters commonParas) {
		HttpSession session = ServletActionContext.getRequest().getSession();
		String posId = (String) session.getAttribute("positionId");
		AuthorityPosBo authposBo = (AuthorityPosBo) SpringBeanFactory
				.getBean("authPosService");
		String deptLocsInCharge[][] = authposBo.getDeptAndLocInCharge(posId,
				Integer.valueOf(4));
		if (deptLocsInCharge == null)
			return;
		IEmployeeBo empBo = (IEmployeeBo) SpringBeanFactory.getBean("empBo");
		List empList = empBo.searchEmpArray(empIdArr);
		String empStr = "";
		IWorkFlowBO workflowBo = (IWorkFlowBO) SpringBeanFactory
				.getBean("workFlowBO");
		Iterator i$ = empList.iterator();
		do {
			if (!i$.hasNext())
				break;
			Employee emp = (Employee) i$.next();
			if ("NOCHARGE".equals(workflowBo.checkEmpCharge(deptLocsInCharge,
					emp)))
				empStr = (new StringBuilder()).append(empStr).append(
						emp.getEmpName()).append("\u3001").toString();
		} while (true);
		if (empStr.length() > 0) {
			empStr = empStr.substring(0, empStr.length() - 1);
			commonParas.addErrorMessage(noAuth, null, new String[] { empStr });
		}
	}

	String noAuth;
	protected IEmployeeBo employeeBo;
}
